<style>
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  .out {
    /* 父相 */
    position: relative;
    width: 400px;
    height: 400px;
    background-color: purple;
  }
  .in {
    /* 子绝 */
    position: absolute;

    /* 水平、垂直居中：父容器一半，自身一半 */
    left: 50%;
    top: 50%;
    /* margin-left: -100px; */
    /* margin-top: -100px; */
    transform: translate(-50%, -50%);

    width: 200px;
    height: 200px;
    background-color: orangered;
  }
</style>

<div class="out">
  <div class="in"></div>
</div>
